package com.ldw.hello.dubbo.service.user.provider.api.impl;

import com.ldw.hello.dubbo.service.user.api.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Value;

/**
 * <p>Title: UserServiceImpl</p>
 * <p>Description: </p>
 *
 * @author: dwLiu
 * @date: 2020/3/5 16:17
 */
@Service(version = "${user.service.version}")
public class UserServiceImpl implements UserService {

    @Value("${dubbo.application.name}")
    private String serviceName;

    @Value("${dubbo.protocol.port}")
    private String port;

    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")})

    @Override
    public String sayHello(String name) {
//        return String.format("[%s] : Hello, %s,port:%s", serviceName, name, port);
        throw new RuntimeException("Exception to show hystrix enabled.");
    }

}
